<template>
  <div>
    <transition appear :name="transitionName">
      <router-view class="child-view"></router-view>
    </transition>
  </div>

</template>

<script>
  export default {
    name: 'app',
    components: {
    },

    watch: {
      '$route' (to, from, next) {
        const toDepth = to.path.split('/').filter(x => Boolean(x)).length
        const fromDepth = from.path.split('/').filter(x => Boolean(x)).length

        if (toDepth === fromDepth) {
          this.transitionName = 'fade'
        }

        if (toDepth > fromDepth) {
          this.transitionName = 'slide-left'
        }

        if (toDepth < fromDepth) {
          this.transitionName = 'slide-right'
        }
      }
    },

    data () {
      return {
        transitionName: 'slide-left'
      }
    },

    created () {
      this.setCookie('msOpenId', 'obhVk0ZkMZHgWf7pFaG_1Isl7fJ8')
      this.setCookie('mstoken', '36f84e64316a44f4b4acdd17bb0094a5')
    },

    methods: {
      // 设置cookie   name为cookie的名字，value是值，expiredays为过期时间（天数）
      setCookie (name, value, expiredays) {
        var exdate = new Date()
        exdate.setDate(exdate.getDate() + expiredays)
        document.cookie = name + '=' + escape(value) + ((expiredays == null) ? '' : ';expires=' + exdate.toGMTString())
      }
    }
  }
</script>

<style lang="less" scoped>
  .child-view {
    position: absolute;
    width:100%;
    transition: all .8s cubic-bezier(.55,0,.1,1);
  }
  .slide-left-enter, .slide-right-leave-active {
    opacity: 0;
    -webkit-transform: translate(100%, 0);
    transform: translate(100%, 0);
  }
  .slide-left-leave-active, .slide-right-enter {
    opacity: 0;
    -webkit-transform: translate(-100%, 0);
    transform: translate(-100%, 0);
  }
</style>
